package h0827;

import java.util.Scanner;

/**
  * @description 编辑距离
  * @author 不知名帅哥
  * @date 2024/8/27 20:40
  * @version 1.0
*/
public class EditDistance {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String s1 = sc.nextLine();
        String s2=sc.nextLine();
        int res=getRes(s1,s2);
        System.out.println(res);
    }

    private static int getRes(String s1, String s2) {
        int m = s1.length();
        int n = s2.length();
        int[][] dp = new int[m+1][n+1];
        dp[0][0]=0;
        //假如s2是空字符
        for (int i = 1; i <= m; i++) {
            dp[i][0]=i;
        }
        //假如s2是空字符
        for (int i = 1; i <= n; i++) {
            dp[0][i]=i;
        }
        for (int i = 1; i < m; i++) {
            for (int j = 1; j < n; j++) {
                if (s1.charAt(i-1)==s2.charAt(j-1)){
                    dp[i][j]=dp[i-1][j-1];
                }else {
                    //插入+1，删除加一，替换
                    dp[i][j]=Math.min(dp[i-1][j]+1,Math.min(dp[i][j-1]+1,dp[i-1][j-1]+1));
                }
            }
        }
        return dp[m-1][n-1];
    }
}
